import { Body, Controller, Get, Post } from '@nestjs/common';
import { INavigationMenu } from 'src/types/navigation_menu';
import { NavigationMenuService } from 'src/services/navigation_menu/navigation_menu.service';
import HttpResponse from 'src/types/http.response.interface';

type UnionType = INavigationMenu[] | INavigationMenu;

@Controller('navigationmenu')
export class NavigationMenuController {


    constructor(private readonly navigationMenuService: NavigationMenuService) {


    }

    @Get('/findAll')
    async findAllActive():Promise<HttpResponse<UnionType>>{
        const data = await this.navigationMenuService.findAllActive({isActive:true});
        if(Array.isArray(data) && data.length>0){
            return {
                success:true,
                message:"数据查询成功",
                data
            }
        } 
        else{
            return {
                success:false,
                message:"数据查询失败",
            }
        }
    }



    /**
    * 用来通过postman 
    * 在浏览器中输入http://localhost:9898/navigationmenu/importData
    */
    @Post("/importData")
    async importData(@Body() requestParamsBody: UnionType): Promise<HttpResponse<UnionType>> {

        const data:UnionType = await this.navigationMenuService.importData(requestParamsBody);
        return {
            success:true,
            message:"导航数据导入成功",
            data
        };
    }


}
